/*******************************************************************************
Project:        Rents
Last modified:  2024-05-16
Description:    This file creates a figure displaying the shares of each type of income earned by wealth quintiles, breaking out additional information at the top. 
*******************************************************************************/

clear all

global home "V:\sthorpe\Rents"
global output "$home\figures"

global gpr = "plotregion(fcolor(white) lcolor(white) m(tiny)) graphregion(fcolor(white) lcolor(white))"

cd "$home"


import excel "burden_distribution_figure.xlsx", firstrow clear

keep in 1/5
drop if category == "norm_returns" | category == "labor_inc"

tempfile t
save `t'

clear
import excel "$home/new_fig_rentsallocation.xlsx", firstrow clear
drop K
keep in 1/5

append using `t'

replace category = ptile if missing(category) 
drop ptile

sort Q5
gen case = _n

drop if category=="cit_burden"


        #delimit ;
        graph hbar Q1 Q2 Q3 Q4 Q5	
            ,
            $gpr stack 
            over(case, relabel(1 "Rents, Fuest" 2 "Labor Income" 3 "Expanded Cash Income" 4 "Rents, Carbonnier" 5 "Rents, Kline" 6 "Supernormal Returns" 7 "Rents, Dobridge")
                lab(labsize(small)))

            legend(order(1 "Quntile 1" 2 "Quntile 2" 3 "Quintile 3"
                         4 "Quintile 4" 5 "Quintile 5")
                    size(small) region(lcolor(white) margin(tiny)) row(2)
                    symxsize(*0.4) position(6))
            bar(1, color(dknavy*1.1) ) 
            bar(2, color(maroon*0.8) ) 
            bar(3, color(dkgreen*1.1) )
            bar(4, color(dkorange*0.8) )
            bar(5, color(teal*1.2) ) 
            xsize(9) ysize(6); 
			
        graph export "$output/distribution_quintiles_fig3.png", replace ;
		#delimit cr 